﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; 
using NTTDATA.BEENChina.ResultCertification.Config; 

namespace NTTDATA.BEENChina.ResultCertification.Checker.Numeric
{
   
    [Serializable]
    [VerfityAttribute(Id = "VerfityD0005", Name = "日期不在列表中抽出", CategoryType = EnumCategoryType.数值, Model = true)]
    public class VerfityD0005 : VerfityOneResult
    { 

        [Category("正确的日期"), Description("正确的日期，逗号分隔")] 
        public string[] RrightDays
        {
            get; set;  
        }

      

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;

            if (entryCommon == "30" || entryCommon == "20")
            {
                return false;
            }

            if (result == null)
            {
                return false;
            }


            bresult = CheckSpecificCharacter(result, GetSpeicficResult, CheckspecificResult); 

           

            if (bresult)
            {
                System.Console.WriteLine("VerfityD0005");
            }

            return bresult;
        }


        private string GetSpeicficResult(string colResult)
        {
            var splitResult = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult);
            if (ChildImageObject.CategorySetting.DataFormat.Contains("md"))
            {
                return splitResult.GetMd();
            }
            else if (ChildImageObject.CategorySetting.DataFormat.Contains("d"))
            {
                return splitResult.GetNumeric();
            }
            
            return colResult;
        }


        private List<int> GetRightDays()
        {
             

            List<int> days = new List<int>();
            foreach (string row in RrightDays)
            {
                int r;

                if (!int.TryParse(row, out r))
                {
                    r = -1;
                }

                days.Add(r);
            }

            return days;

        }
        private bool CheckspecificResult(string result)
        {
            bool bresult = false; 


            if (!String.IsNullOrEmpty(result))
            {

                var rightDays = GetRightDays();
                var days = result.Split(new char[] { '.' }).ToList();

                foreach (string day in days)
                {                    
                    //if (day.Equals("0") || new NumericComparer().Compare(day, "31") > 0)
                    //{
                    //    bresult = true;
                    //}
                    int d = -1;

                    if (!int.TryParse(day, out d))
                    {
                        d = -1;
                    }

                    if ( d > -1)
                    {
                        bresult = !rightDays.Contains(d);
                    }
                    if (bresult)
                        break;
                }
 
            }
            return bresult;
        }


    }
}
